﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Media;
using System.Windows.Shapes;

namespace UBCon.Ribbon
{
    public class ApplicationMenuDecorator : Adorner
    {
        public ApplicationMenuDecorator(UIElement adorndedElement):
            base(adorndedElement) 
        {
        }

        protected override Size MeasureOverride(Size constraint)
        {
            if(this.AdornedElement!=null&&this.AdornedElement is FrameworkElement)
            {
                FrameworkElement elt = this.AdornedElement as FrameworkElement;
                Size s = new Size(this.RootWindow.ActualWidth-1, this.RootWindow.ActualHeight-1);
                this.Content.Measure(s);
                return s;
            }

            return base.MeasureOverride(constraint);
        }

        protected override Size ArrangeOverride(Size finalSize)
        {

            if (this.AdornedElement != null && this.AdornedElement is FrameworkElement)
            {
                FrameworkElement elt = this.AdornedElement as FrameworkElement;
                this.Content.Arrange(new Rect(0, 0, finalSize.Width-1, finalSize.Height-1));
                return finalSize;
            }

            return base.ArrangeOverride(finalSize);
        }


        internal Window RootWindow = null;

        internal FrameworkElement Content { get; set; }
        
        protected override Visual GetVisualChild(int index)
        {
            return this.Content;
        }

        protected override int VisualChildrenCount
        {
            get
            {
                return 1;
            }
        }
    }
}
